<template>
	<div class="edit-LeaveApply-container">
		<el-dialog title="编辑请假申请" v-model="isShowDialog" width="756px">
			<el-form :model="ruleForm" :rules="rules" ref="form" size="small" label-width="120px">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="请假天数" prop="day">
							<el-input-number v-model="ruleForm.day" placeholder="请输入请假天数" :precision="1" :step="0.5"
								step-strictly clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="请假类型" prop="type">
							<el-select v-model="ruleForm.type" placeholder="请输入请假类型" maxlength="32" clearable>
								<el-option v-for="item in leaveType" :key="item.id" :label="item.name"
									:value="+item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="开始时间" prop="startTime">
							<el-date-picker v-model="ruleForm.startTime" type="datetime" placeholder="请输入开始时间"
								maxlength="32" value-format="YYYY-MM-DD HH:mm:ss" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="结束时间" prop="endTime">
							<el-date-picker v-model="ruleForm.endTime" type="datetime" placeholder="请输入结束时间"
								maxlength="32" value-format="YYYY-MM-DD HH:mm:ss" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="请假原因" prop="remark">
							<el-input v-model="ruleForm.remark" placeholder="请输入请假原因" type="textarea" autosize
								clearable />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="small">取 消</el-button>
					<el-button type="primary" @click="submitForm(form, onSubmit)" size="small">保 存</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref, defineExpose, onMounted } from 'vue';
import { update, LeaveApply } from '/@/api/sys/leaveApply';
import { detailByCode, SysDictDetail } from "/@/api/sys/dict";
import { submitForm } from '/@/utils/form';
import { rule } from './rule';
const form = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {
		day: 0, // 请假天数
		type: 0, // 请假类型
		startTime: '', // 开始时间
		endTime: '', // 结束时间
		remark: '', // 请假原因
		status: 0, // 流程状态
		processId: '', // 流程实例id
	} as LeaveApply,
	rules: rule,
	leaveType: [] as SysDictDetail[],
});
// 打开弹窗
const openDialog = (row: any) => {
	state.ruleForm = row;
	state.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	state.isShowDialog = false;
};
// 取消
const onCancel = () => {
	closeDialog();
};
// 保存
const onSubmit = () => {
	update(state.ruleForm).then(() => {
		closeDialog();
	})
};

onMounted(() => {
	detailByCode('leaveType').then(res => {
		state.leaveType = res.data
	})
});

const { isShowDialog, ruleForm, rules, leaveType } = toRefs(state);

defineExpose({
	openDialog,
})
</script>
